package com.example.demo3.others;


import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class Login {
    @PostMapping("/login")
    public Boolean p1(String userName,String password,HttpSession session){
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)){
            return false;
        }

        if("admin".equals(userName) && "admin".equals(password)){
            session.setAttribute("userName",userName);
            return true;
        }
        return false;
    }

    @RequestMapping(value="/getLoginUser",method= RequestMethod.GET)
    public String p2(HttpSession session){
        if(session.getAttribute("userName") != null){
            return (String)session.getAttribute("userName");
        }
        return "";
    }

}
